package com.yjkf.zh.admin.service.impl;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.yjkf.zh.admin.service.SysAliyunIotService;
import com.yjkf.zh.admin.util.SysConstant;
import com.yjkf.zh.core.http.HttpResult;
import org.springframework.stereotype.Service;

@Service
public class SysAliyunIotServiceImpl implements SysAliyunIotService {

    String accessKey = SysConstant.AccessKey;
    String accessSecret = SysConstant.AccessSecret;
    String regionId = SysConstant.regionId;
    String domain=SysConstant.domain;
    String version=SysConstant.version;
    String requestId=SysConstant.regionId;

    @Override
    public Object aliyunIotService(String productKey,String deviceName,String action) {

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.GET);
        request.setSysDomain(domain);
        request.setSysVersion(version);
        request.setSysAction(action);
        request.putQueryParameter("RegionId", regionId);
        request.putQueryParameter("ProductKey", productKey);
        request.putQueryParameter("DeviceName", deviceName);
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKey, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
        Object result = null;
        try {
            CommonResponse response = client.getCommonResponse(request);
            result = response.getData();
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }

       return result;
    }
}
